package utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class EncryptionUtils {

	public static String ConvertToMD5(String pwd){ 
		MessageDigest md;
		try {
			md = MessageDigest.getInstance("MD5");
			byte[] b = md.digest(pwd.getBytes());
		    int size = b.length;
		    StringBuffer h = new StringBuffer(size);
		    //algorithm to mend md5
		    for (int i = 0; i < size; i++) {
		    	int u = b[i] & 255;
		        if (u < 16) {h.append("0" + Integer.toHexString(u));}
		        else {h.append(Integer.toHexString(u));}
		    }
		    //encrypted password
		    return h.toString();
		
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
			return null;
		}
	    
	}
	public static void main(String[] args) {
		System.out.println("eduard;informatica01;" +EncryptionUtils.ConvertToMD5("informatica01"));
		System.out.println("user01;informatica02;" +EncryptionUtils.ConvertToMD5("informatica02"));

	}

}
